package ui.manager;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

import tool.MyButton;
import tool.MyLabel;
import ui.accountbook.AccountBookManagePanel;
import ui.approval.单据审批panel;
import ui.finance.收付款单Panel;
import ui.finance.现金费用单Panel;
import ui.history.BusinessConditionPanel;
import ui.history.BusinessProgressPanel;
import ui.history.SaleLogPanel;
import ui.history.SystemLogPanel;
import ui.strategy.CouponsPanel;
import ui.strategy.DiscountPackagePanel;
import ui.strategy.DiscountPanel;
import ui.strategy.GiftPanel;
import vo.UserVo;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import o.财务单据类型;

public class ManagerFrame extends JFrame {

	private static final long serialVersionUID = -3485967379197888026L;
	UserVo user;
	JPanel panel;

	public ManagerFrame(UserVo user) {

		this.setContentPane(new JPanel() {

			private static final long serialVersionUID = -8067534092982934270L;

			@Override
			public void paint(Graphics g) {
				this.setBackground(new Color(0, 0, 0, 0));
				Image background = Toolkit.getDefaultToolkit().getImage(
						"Graphics/framebackground.jpg");
				g.drawImage(background, 0, 0, null);
				super.paint(g);
			}
		});

		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new WindowListener() {

			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}

			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub

			}
		});

		this.user = user;
		this.setSize(850, 536);
		this.setTitle("总经理");
		getContentPane().setLayout(null);

		JButton button = new MyButton("Graphics/Button120-23.png");
		button.setText("主界面");
		button.setBounds(10, 30, 120, 23);
		getContentPane().add(button);
		button.addActionListener(e -> ManagerFrameWelcomeManagement());

		JLabel label_3 = new MyLabel("单据审批");
		label_3.setForeground(Color.WHITE);
		label_3.setBounds(45, 63, 100, 23);
		getContentPane().add(label_3, BorderLayout.SOUTH);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

		JButton button_1 = new MyButton("Graphics/Button120-23.png");
		button_1.setText("单据审批");
		button_1.setBounds(10, 96, 120, 23);
		getContentPane().add(button_1);
		button_1.addActionListener(e -> djspManagement());

		JLabel label = new MyLabel("销售策略制定");
		label.setForeground(Color.WHITE);
		label.setBounds(30, 129, 100, 15);
		getContentPane().add(label);

		JButton button_2 = new MyButton("Graphics/Button120-23.png");
		button_2.setText("赠品");
		button_2.setBounds(10, 154, 120, 23);
		getContentPane().add(button_2);
		button_2.addActionListener(e -> strategy_gift());

		JButton button_3 = new MyButton("Graphics/Button120-23.png");
		button_3.setText("价格折让");
		button_3.setBounds(10, 187, 120, 23);
		getContentPane().add(button_3);
		button_3.addActionListener(e -> strategy_discount());

		JButton button_8 = new MyButton("Graphics/Button120-23.png");
		button_8.setText("特价包");
		button_8.setBounds(10, 220, 120, 23);
		getContentPane().add(button_8);
		button_8.addActionListener(e -> strategy_discountPackage());

		JButton button_9 = new MyButton("Graphics/Button120-23.png");
		button_9.setText("代金券");
		button_9.setBounds(10, 253, 120, 23);
		getContentPane().add(button_9);
		button_9.addActionListener(e -> strategy_coupons());

		JLabel label_1 = new MyLabel("表单查询");
		label_1.setForeground(Color.WHITE);
		label_1.setBounds(45, 286, 100, 15);
		getContentPane().add(label_1);

		JButton button_4 = new MyButton("Graphics/Button120-23.png");
		button_4.setText("销售明细表");
		button_4.setBounds(10, 311, 120, 23);
		getContentPane().add(button_4);
		button_4.addActionListener(e -> xsmxManagement());

		JButton button_5 = new MyButton("Graphics/Button120-23.png");
		button_5.setText("经营历程表");
		button_5.setBounds(10, 344, 120, 23);
		getContentPane().add(button_5);
		button_5.addActionListener(e -> jylcManagement());

		JButton button_6 = new MyButton("Graphics/Button120-23.png");
		button_6.setText("经营情况表");
		button_6.setBounds(10, 377, 120, 23);
		getContentPane().add(button_6);
		button_6.addActionListener(e -> jyqkManagement());

		JButton button_10 = new MyButton("Graphics/Button120-23.png");
		button_10.setText("系统日志");
		button_10.setBounds(10, 410, 120, 23);
		getContentPane().add(button_10);
		button_10.addActionListener(e -> xtrzManagement());

		// 显示欢迎界面
		ManagerFrameWelcomeManagement();
	}

	// 制定赠品策略
	public void strategy_gift() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new GiftPanel(user, null, true);// 赠品策略
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void strategy_coupons() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new CouponsPanel(user, null, true);// 代金券策略
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void strategy_discount() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new DiscountPanel(user);// 价格折让策略
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void strategy_discountPackage() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new DiscountPackagePanel(user,true);// 特价包策略
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void zmglManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new AccountBookManagePanel(user);// 账目管理
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void jyqkManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new BusinessConditionPanel(user);// 经营情况表
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void jylcManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new BusinessProgressPanel(user);// 经营历程表
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void xsmxManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SaleLogPanel(user);// 销售明细表
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void xjfydManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 现金费用单Panel(user, null, true, false, false);// 现金费用单
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void fkdManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 收付款单Panel(user, null, true, 财务单据类型.付款单, false, false);// 付款单
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void skdManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 收付款单Panel(user, null, true, 财务单据类型.收款单, false, false);// 收款单
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void djspManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 单据审批panel(user);
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void ManagerFrameWelcomeManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new ManagerWelcomePanel();// 欢迎
		panel.setForeground(Color.WHITE);
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}

	public void xtrzManagement() {
		if (panel != null) {
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SystemLogPanel(user);
		panel.setBounds(160, 40, 646, 433);
		getContentPane().add(panel);
	}
}
